/*
 * TerrainMap.h
 *
 *  Created on: Mar 13, 2010
 *      Author: Vu Phuong Hoang
 */

#ifndef TERRAINMAP_H_
#define TERRAINMAP_H_

template<class T>
class TerrainMap {
private:
	unsigned int uiRows, uiColumns;
	T** ppkMap;
public:
	TerrainMap() :
		uiRows( 0 ), uiColumns( 0 ), ppkMap( NULL ) {
	}
	TerrainMap(const unsigned int rows, const unsigned int columns, T** map) :
		uiRows( rows ), uiColumns( columns ), ppkMap( map ) {
	}
	void setMap(const unsigned int rows, const unsigned int columns, T** map);
	T get(const unsigned int x, const unsigned int y);
	unsigned int getRows();
	unsigned int getColumns();
	bool isInMap(const unsigned int x, const unsigned int y);
	bool isMapAvailable();
};

template<class T>
void TerrainMap<T>::setMap(const unsigned int rows, const unsigned int columns, T** map) {
	this->uiRows = rows;
	this->uiColumns = columns;
	this->ppkMap = map;
}

template<class T>
T TerrainMap<T>::get(const unsigned int x, const unsigned int y) {
	if (!isInMap( x, y )) {
		return ppkMap[0][0];
	} else {
		return ppkMap[x][y];
	}
}

template<class T>
unsigned int TerrainMap<T>::getRows() {
	return uiRows;
}

template<class T>
unsigned int TerrainMap<T>::getColumns() {
	return uiColumns;
}

template<class T>
bool TerrainMap<T>::isInMap(const unsigned int x, const unsigned int y) {
	return ((x >= 0) && (x < uiRows) && (y >= 0) && (y < uiColumns));
}

template<class T>
bool TerrainMap<T>::isMapAvailable() {
	return ((uiRows > 0) && (uiColumns > 0) && (ppkMap != NULL));
}

#endif /* TERRAINMAP_H_ */
